<?
	$section = 'Products';
	include_once("Header.php");
    require_once('../DatabaseProject/EcsProductsMgmt/ProductsData.php');
    $result = GetProducts();
?>

	<div class="content">
	Product Page
	</div>
<div id="tableWrapper">
<table border="1">
                        <tr>
                       
            					<th>Action</th>
         				        <th>Product Name</th>
                                <th>Manufacturer</th>
                                <th>Condition</th>
                                <th>Sport Type</th>
                                <th>Product Type</th>
                                <th>Sale Price</th>
                       <?if(isset($_SESSION['UserEmail']))
        				{
        					if(GetUserClearance() == 'Administrator')
        					{        
        					?>
            					<th>Cost</th>
         					<?}
        				}?>
                                <th>Quantity</th>      
                         <?if(GetUserClearance() !='Administrator')
        					{?>
            					<th>Cart Options</th>
        				   <?}?>
                        </tr>
       
        <? while($rs = $result->fetch_assoc()){ ?>
                <tr>
                		<td>
                                <a href="View.php?ID=<?=$rs['ID']?>">View</a>
                		<?if(isset($_SESSION['UserEmail']))
        				{
        					if(GetUserClearance() == 'Administrator')
        					{        
        					?>
            			
                                <a href="EditUser.php?ID=<?=$rs['ID']?>">Edit</a>
                                <a href="Delete.php?ID=<?=$rs['ID']?>">Delete</a>
                               
                        </td>
         					<?}
        				}?>
                        <td><?=$rs['ProductName']?></td>
                        <td><?=$rs['Manufacturer']?></td>
                        <td><?=$rs['Condit']?></td>
                        <td><?=$rs['Sport_Type']?></td>
                        <td><?=$rs['Product_Type']?></td>
                        <td align="right">&#36;<?=$rs['SalePrice']?></td>
                         <?if(isset($_SESSION['UserEmail']))
        				{
        					if(GetUserClearance() == 'Administrator')
        					{        
        					?>
            					<td align="right">&#36;<?=$rs['Cost']?></td>
         					<?}
        				}?>
                        <td align="center"><?=$rs['Quantity']?></td>
                 
       					<?if(GetUserClearance() != 'Administrator')
        					{        
        					?>
        						<?if($rs['Quantity'] > 0)
        						{?>
            					<td>
       						<input type="button" value="Add to Cart" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/WebClass/ECommSite/CartController.php?action=add&ID=<?=$rs['ID']?>'"/>       						
       							</td>
       							<?}else 
       							{
       								?><td id="notify">Out of Stock</td><?
       							}?>
         					<?}?>
       			</tr> 
        <? } ?>
        		
       
</table>
</div>
<div>
<?if(isset($_SESSION['UserEmail']))
{
	if(GetUserClearance() == 'Administrator')
    {        
 	?>
		<a href="../ConnectMethMgmt/EditConnectMeth.php"><b>Click here to add a new Product.</b></a>
	<?}
}?>

</div>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$.get("Controller.php?action=new",function(data){
				$("#tableWrapper").append(data);
			});
			$("form").live('submit',function(){
				var form = $(this);
				$.post(form.attr('action'), form.serialize(), function(data){
					record_row = form.closest(".record_row");
					if(record_row.length == 0)
						$("table:eq(0)").append(data);
					else
						record_row.replaceWith(data);
				});
                                
				return false;
				
			})
		
			$('.edit_link').live('click',function(){
				var editlink = $(this);
				$.get("Controller.php?action=edit&id=" + editlink.attr('data-id'),function(data){
					editlink.closest("tr").find("td").hide();
					formTd = $("<td></td>")
						.attr("colspan",4)
						.html(data)
						.appendTo(editlink.closest("tr"));
					formTd.find("select").each(function(){
						$(this).val($(this).attr('data-value'));
					});
				});
			return false;
				});
			});
			$('.cancel_link').live('click',function(){
				$(this).closest(".record_row").find("td").show();
				$(this).closest("form").closest("td").detach();
				return false;
			});
			$('.delete_link').live('click',function(){
			record_row = $(this).closest(".record_row");
			$.post(this.href,function(data){
			if(data == 'Success')
			{
				record_row.hide('slow');
			}
			});
		return false;
	});
</script>
	<div>	
	<!-- <input type="button" value="Products" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/WebClass/DatabaseProject/EcsProductsMgmt/'" />-->
	
	</div>
</body>
</html>
